package com.example.ioc;

import com.example.common.utils.Statistics;
import com.example.ioc.context.LApplicationContextInitializer;
import com.example.ioc.context.LBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Import;

/**
 * <p>
 *     下列类在<br>
 *     {@link org.springframework.context.annotation.ConfigurationClassPostProcessor}
 *     中处理:<br>
 *     {@link org.springframework.context.annotation.ImportResource}
 *     {@link Import}
 *     {@link org.springframework.context.annotation.ComponentScan}
 *     {@link org.springframework.stereotype.Component}
 *     {@link org.springframework.context.annotation.Configuration}
 *     {@link org.springframework.context.annotation.Bean}
 * </p>
 * spring自带很多很重要的<br>
 * {@link org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor}
 * 的实现类: <br>
 * 1. {@link  org.springframework.context.annotation.ConfigurationClassPostProcessor}<br>
 * 它将被{@link org.springframework.context.annotation.Configuration} 注解的类的被<br>
 * {@link org.springframework.context.annotation.Bean}<br>
 * 注解的方法以及 被{@link org.springframework.stereotype.Component}(以及它的子类)注解的类注册为<br>
 * {@link org.springframework.beans.factory.config.BeanDefinition}
 *
 *<p>
 *     也很多{@link org.springframework.beans.factory.config.BeanFactoryPostProcessor}<br>
 *     的实现类.<br>
 *     1.{@link org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor}<br>
 *</p>
 *
 *
 * {@link org.springframework.context.annotation.ConfigurationClassPostProcessor}
 */
@Slf4j
@SpringBootApplication
public class IocApplication {

    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(IocApplication.class);
        app.addInitializers(LApplicationContextInitializer.getInstance());
//        app.setLazyInitialization(true);//设置全局懒加载
//        app.addListeners(new LApplicationListener());
        ConfigurableApplicationContext context = app.run(args);
        try{
            context.getBean(LBean.MyBean.class);
        }catch (Exception ignore){}
        try {
            context.getBean(LBean.class);
        }catch (Exception ignore){}
        Statistics.logInfo(log, "main", "应用启动完成");
//        context.getBean("lifeCycleBeanFactoryBean");
//        context.getBean("lifeCycleBean");
//        context.getBean("myBeanFactoryBean");
        context.close();
    }

}
